package com.cloud.pole.param.biz;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.api.param.ParamAreaApi;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.ParamAreaMapper;
import com.cloud.pole.param.model.entity.ParamArea;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
@Transactional(rollbackFor = Exception.class)
public class ParamAreaBiz extends BaseBiz<ParamAreaMapper,ParamArea> {

	@Cache(key="paramArea:list{1}")
	public List<ParamArea> selectAreaList(String fatherCode, Integer type){
		 Example example = new Example(ParamArea.class);
		 Criteria criteria = example.createCriteria();
         example.setOrderByClause("order_level");
         if(!StringUtils.isEmpty(fatherCode) && !StringUtils.equals(fatherCode, ParamAreaApi.AREA_CODE_ROOT)) {
             criteria.andLike("code", "%"+ fatherCode +"%");
         }
		 criteria.andEqualTo("type", type);
		 return selectByExample(example);
	}
	
	@Cache(key="paramArea:code{1}")
	public ParamArea selectByPrimaryKey(String code) {
		return super.selectById(code);
	}
	
    @CacheClear(keys = {"paramArea"})
    public void deleteByPrimaryKey(String id) {
        super.deleteById(id);
    }
}
